﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ordinapoche
{
    public static class Instruction
    {
        public static int Build (OpCode aOpcode, int aAddress)
        {
            if (0 <= aAddress && aAddress < 100)
            {
                return (int)aOpcode * 100 + aAddress;
            }
            else
            {
                return 900;
            }
        }

        public static void Split (int aInstruction, out OpCode aOpcode, out int aAddress)
        {
            if (0 <= aInstruction && aInstruction <= 999)
            {
                aAddress = aInstruction % 100;
                aOpcode = (OpCode)(aInstruction / 100);
            }
            else
            {
                aOpcode = OpCode.HRS;
                aAddress = 0;
            }
        }

        public static int Inp (int aAddress)
        {
            return Build (OpCode.INP, aAddress);
        }
        public static int Out (int aAddress)
        {
            return Build (OpCode.OUT, aAddress);
        }
        public static int Cla (int aAddress)
        {
            return Build (OpCode.CLA, aAddress);
        }
        public static int Sto (int aAddress)
        {
            return Build (OpCode.STO, aAddress);
        }
        public static int Add (int aAddress)
        {
            return Build (OpCode.ADD, aAddress);
        }
        public static int Sub (int aAddress)
        {
            return Build (OpCode.SUB, aAddress);
        }
        public static int Jmp (int aAddress)
        {
            return Build (OpCode.JMP, aAddress);
        }
        public static int Tac (int aAddress)
        {
            return Build (OpCode.TAC, aAddress);
        }
        public static int Hrs (int aAddress)
        {
            return Build (OpCode.HRS, aAddress);
        }

    }
}
